<?php

	class EbModel
	{
		static private $listModelInstances = array();
		
		static public $defaultDataSource;
		static private $listDataSources = array();
				
		static function init()
		{
			self::$listDataSources = EbApplication::$listDataSources;
		}		
				
		static function getModel($module,$name)
		{		
			if (!isset(self::$listModelInstances[$module."_".$name]))
			{
				self::$listModelInstances[$module."_".$name] = eb_module_file_new_instance($module,$name,MODULE_FILE_MODEL);
				
				if (!is_null(EbApplication::$debug))
				{
					EbApplication::$debug->addModel($module." / ".$name);
				}
			}
			
			
			
			//$listModelInstances[$module."/".$name] = new CRUDSQLModel();
			//$listModelInstances[$module."/".$name]->init(eb_get_module_file_vo($module,$name,MODULE_FILE_VO));
			
			return self::$listModelInstances[$module."_".$name];
		}
		
		static public function getDataSource($source = 0)
		{
			if (isset(self::$listDataSources[$source]))
			{
				return self::$listDataSources[$source];
			}
			else
			{
				throw new Exception("The data source '$source' does not exist!");
			}
		}		
	}